package com.ctgu.ImageRecognition.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ctgu.ImageRecognition.entity.User;
import com.ctgu.ImageRecognition.dao.UserDao;
import com.ctgu.ImageRecognition.service.UserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表服务实现类
 *
 * @author 
 * @since 2023-07-05 18:31:03
 */
//@Service("userService")
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;


    @Override
    public List<User> test() {
        return userDao.selectList(null);
    }

    @Override
    public User login(String username) {
        QueryWrapper<User> selectWrapper = new QueryWrapper<>();
        selectWrapper.eq("username",username);
        return userDao.selectOne(selectWrapper);
    }

    @Override
    public int register(User user) {
        return userDao.insert(user);
    }

    @Override
    public int save(User user) {
        System.out.println("user = " + user.toString());
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("u_id",user.getUId());
        if(user.getUsername() != null){updateWrapper.set("username",user.getUsername());}
        if(user.getPassword() != null){updateWrapper.set("password",user.getPassword());}
        return userDao.update(null,updateWrapper);
    }


}
